2000W / 48V LLC Battery-Charger  V1.00
xmc1_gpio.c
Go to the documentation of this file.
1 
52 #include "xmc_gpio.h"
53 
54 #if UC_FAMILY == XMC1
55 
56 /*******************************************************************************
57  * MACROS
58  *******************************************************************************/
59 
60 #define PORT_PHCR_Msk PORT0_PHCR0_PH0_Msk
61 #define PORT_PHCR_Size PORT0_PHCR0_PH0_Msk
62 #define PORT_HWSEL_Msk PORT0_HWSEL_HW0_Msk
63 #define XMC_GPIO_MODE_OE XMC_GPIO_MODE_OUTPUT_PUSH_PULL
64 
65 /*******************************************************************************
66  * API IMPLEMENTATION
67  *******************************************************************************/
68 
69 void XMC_GPIO_Init(XMC_GPIO_PORT_t *const port, const uint8_t pin, const XMC_GPIO_CONFIG_t *const config)
70 {
71  XMC_ASSERT("XMC_GPIO_Init: Invalid port", XMC_GPIO_CHECK_PORT(port));
72  XMC_ASSERT("XMC_GPIO_Init: Invalid mode", XMC_GPIO_IsModeValid(config->mode));
73  XMC_ASSERT("XMC_GPIO_Init: Invalid input hysteresis", XMC_GPIO_CHECK_INPUT_HYSTERESIS(config->input_hysteresis));
74 
75  /* Switch to input */
76  port->IOCR[pin >> 2U] &= ~(uint32_t)((uint32_t)PORT_IOCR_PC_Msk << (PORT_IOCR_PC_Size * (pin & 0x3U)));
77 
78  /* HW port control is disabled */
79  port->HWSEL &= ~(uint32_t)((uint32_t)PORT_HWSEL_Msk << ((uint32_t)pin << 1U));
80 
81  /* Set input hysteresis */
82  port->PHCR[(uint32_t)pin >> 3U] &= ~(uint32_t)((uint32_t)PORT_PHCR_Msk << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U)));
83  port->PHCR[(uint32_t)pin >> 3U] |= (uint32_t)config->input_hysteresis << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U));
84 
85  /* Enable digital input */
86  if (XMC_GPIO_CHECK_ANALOG_PORT(port))
87  {
88  port->PDISC &= ~(uint32_t)((uint32_t)0x1U << pin);
89  }
90  else
91  {
92  if ((config->mode & XMC_GPIO_MODE_OE) != 0)
93  {
94  /* If output is enabled */
95 
96  /* Set output level */
97  port->OMR = (uint32_t)config->output_level << pin;
98  }
99  }
100 
101  /* Set mode */
102  port->IOCR[pin >> 2U] |= (uint32_t)config->mode << (PORT_IOCR_PC_Size * (pin & 0x3U));
103 }
104 
105 void XMC_GPIO_SetInputHysteresis(XMC_GPIO_PORT_t *const port,
106  const uint8_t pin,
107  const XMC_GPIO_INPUT_HYSTERESIS_t hysteresis)
108 {
109  XMC_ASSERT("XMC_GPIO_SetInputHysteresis: Invalid port", XMC_GPIO_CHECK_PORT(port));
110  XMC_ASSERT("XMC_GPIO_SetInputHysteresis: Invalid input hysteresis", XMC_GPIO_CHECK_INPUT_HYSTERESIS(hysteresis));
111 
112  port->PHCR[(uint32_t)pin >> 3U] &= ~(uint32_t)((uint32_t)PORT_PHCR_Msk << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U)));
113  port->PHCR[(uint32_t)pin >> 3U] |= (uint32_t)hysteresis << ((uint32_t)PORT_PHCR_Size * ((uint32_t)pin & 0x7U));
114 }
115 
116 #endif /* UC_FAMILY == XMC1 */
#define PORT_HWSEL_Msk
Definition: xmc1_gpio.c:62
#define PORT_IOCR_PC_Msk
Definition: xmc_gpio.h:98
#define XMC_ASSERT(msg, exp)
Definition: xmc_common.h:132
#define XMC_GPIO_MODE_OE
Definition: xmc1_gpio.c:63
void XMC_GPIO_Init(XMC_GPIO_PORT_t *const port, const uint8_t pin, const XMC_GPIO_CONFIG_t *const config)
Definition: xmc1_gpio.c:69
void XMC_GPIO_SetInputHysteresis(XMC_GPIO_PORT_t *const port, const uint8_t pin, const XMC_GPIO_INPUT_HYSTERESIS_t hysteresis)
Definition: xmc1_gpio.c:105
#define PORT_IOCR_PC_Size
Definition: xmc_gpio.h:100
#define PORT_PHCR_Msk
Definition: xmc1_gpio.c:60
#define PORT_PHCR_Size
Definition: xmc1_gpio.c:61